<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="ltr">|Lorem <div  dir="ltr">ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">|Lorem <div dir="ltr">ipsum dolor sit</div> amet</div>',
  `${behavior} 9-0 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">L|orem <div  dir="ltr">ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">|L^orem <div dir="ltr">ipsum dolor sit</div> amet</div>',
  `${behavior} 9-1 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lo|rem <div  dir="ltr">ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">|Lo^rem <div dir="ltr">ipsum dolor sit</div> amet</div>',
  `${behavior} 9-2 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lor|em <div  dir="ltr">ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">|Lor^em <div dir="ltr">ipsum dolor sit</div> amet</div>',
  `${behavior} 9-3 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lore|m <div  dir="ltr">ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">|Lore^m <div dir="ltr">ipsum dolor sit</div> amet</div>',
  `${behavior} 9-4 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem| <div  dir="ltr">ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">|Lorem^ <div dir="ltr">ipsum dolor sit</div> amet</div>',
  `${behavior} 9-5 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">|ipsum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem |<div dir="ltr">^ipsum dolor sit</div> amet</div>',
  `${behavior} 9-6 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">i|psum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">|i^psum dolor sit</div> amet</div>',
  `${behavior} 9-7 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ip|sum dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">|ip^sum dolor sit</div> amet</div>',
  `${behavior} 9-8 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ips|um dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">|ips^um dolor sit</div> amet</div>',
  `${behavior} 9-9 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsu|m dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">|ipsu^m dolor sit</div> amet</div>',
  `${behavior} 9-10 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum| dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">|ipsum^ dolor sit</div> amet</div>',
  `${behavior} 9-11 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum |dolor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">|ipsum ^dolor sit</div> amet</div>',
  `${behavior} 9-12 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum d|olor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum |d^olor sit</div> amet</div>',
  `${behavior} 9-13 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum do|lor sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum |do^lor sit</div> amet</div>',
  `${behavior} 9-14 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dol|or sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum |dol^or sit</div> amet</div>',
  `${behavior} 9-15 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolo|r sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum |dolo^r sit</div> amet</div>',
  `${behavior} 9-16 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor| sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum |dolor^ sit</div> amet</div>',
  `${behavior} 9-17 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor |sit</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum |dolor ^sit</div> amet</div>',
  `${behavior} 9-18 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor s|it</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor |s^it</div> amet</div>',
  `${behavior} 9-19 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor si|t</div> amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor |si^t</div> amet</div>',
  `${behavior} 9-20 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor sit</div>| amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor sit|</div>^ amet</div>',
  `${behavior} 9-21 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor sit</div> |amet</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor sit|</div>^ amet</div>',
  `${behavior} 9-22 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor sit</div> a|met</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor sit</div> |a^met</div>',
  `${behavior} 9-23 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor sit</div> am|et</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor sit</div> |am^et</div>',
  `${behavior} 9-24 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor sit</div> ame|t</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor sit</div> |ame^t</div>',
  `${behavior} 9-25 ltr backward word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <div  dir="ltr">ipsum dolor sit</div> amet|</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="ltr">Lorem <div dir="ltr">ipsum dolor sit</div> |amet^</div>',
  `${behavior} 9-26 ltr backward word`);
}
</script>
